package com.tonghe.service;

import com.tonghe.domain.entity.LoginUser;
import com.tonghe.utils.SecurityUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/***
* 自定义权限实现
* @author: TongHe
* @date: 2022/9/12 11:17
*/
@Service("ps")
public class PermissionService {

    /**
     * 验证用户是否具备某权限
     *
     * @param permission 权限字符串
     * @return 用户是否具备某权限
     */
    public boolean hasPermi(String permission)
    {
        if(SecurityUtils.isAdmin()) {
            return true;
        }
        List<String> permissions = SecurityUtils.getLoginUser().getPermissions();
        return permissions.contains(permission);
    }


}
